/***
 *
 * 封装一个全局message 组件
 * 1、全局时间段内 只提示一次
 * 2、增加提示关闭后的回调方法
 *
 */


import { Message } from '@arco-design/web-vue'
import '@arco-design/web-vue/lib/message/style/index.css';
const showMessage = Symbol('showMessage')
//全局唯一标识符
let messageInstance = null
// 封装message类
class MessageBox {
    success(text , callback) {
        this[showMessage]('success', text , callback)
    }
    error(text , callback) {
        this[showMessage]('error', text , callback)
    }
    warning(text , callback) {
        this[showMessage]('warning', text , callback)
    }
    info(text , callback) {
        this[showMessage]('info', text , callback)
    }
    [showMessage](type, text , callback) {
        if(!messageInstance){
            messageInstance = Message[type]({
                content:text,
                onClose:()=>{
                    // 调用回调方法
                    if(callback instanceof Function){
                        callback()
                    }
                    messageInstance = null
                }
            })
        }
    }
}

export default MessageBox